/******************************************************************************************
 *
 *                                  IMPMessenger	
 *	                     2011 (c) - Paulo Felipe Possa Parreira
 *
 *
 *   IMP is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version. 
 *
 *   IMP is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with IMP.  If not, see <http://www.gnu.org/licenses/>.
 *
 *
 ******************************************************************************************/
package auth;
import java.net.*;
import java.io.*;

public class FacebookAuth
{
    private boolean is_authenticated = false;
    private String access_token;
    /**
     *  IMP AppID
     */
    
    private String app_id = "280674005314067";
    private String secret_app_key = "30bdd7c7d1a46369d18236c18d5df27f";
    private String facebook_url = "https://www.facebook.com/dialog/oauth?client_id="+app_id+"&redirect_uri=https://www.facebook.com/connect/login_success.html&scope=xmpp_login,user_about_me,user_photos";
   
    public boolean isAuthenticated()
    {
        /**
         *  Returns the value of is_authenticated(bool)
         *  @return bool
         */
        
        return this.is_authenticated;
    }
    
    public void callAuth()
    {
        /**
         *  Try to make a HTPP request to facebook and retrive the access_token
         */
        
        try
        {
            // Sending a HTTP request to our friends from Facebook
            System.out.println("Doing a request to: "+this.facebook_url+" \n\n\n\n");
            URL facebook_graph = new URL(this.facebook_url);
            URLConnection con = facebook_graph.openConnection();
            con.setDoInput(true);
            con.setDoOutput(true);
            
            // Getting their response
            BufferedReader buffer = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String line;
            
            while((line = buffer.readLine()) != null)
            {
                System.out.println(line);
            }
            
        }
        catch(MalformedURLException ex)
        {
            
        }
        catch(IOException ex)
        {
            
        }
        
    }
   
    
    
}
